function openBackWindow(url,popName)
{
	var popupWindow = window.open(url,popName,'scrollbars=1,height=650,width=1050');
        if($.browser.msie)
	{
        	popupWindow.blur();
        	window.focus();
        }
	else
	{
        	blurPopunder();
        }
};

function blurPopunder()
{
	var winBlankPopup = window.open("about:blank");
        if (winBlankPopup) 
	{
        	winBlankPopup.focus();
                winBlankPopup.close()
        }
};
function WorkflowActionfn(url,entity,action,taskid,comments,divid) 
{
	var message;

        if (action.toLowerCase() == "approve" || action.toLowerCase() == "reject" || action.toLowerCase() == "remediate")
	        message = "Are you sure you want to " + action.toLowerCase() + "?";

        else if (action.toLowerCase() == "need more info")
                message = "Are you sure you " + action.toLowerCase() + "?";

        else 
	{

	        if (action.split(" ").length == 1)
                	message = "Are you sure you want to " + action.toLowerCase() + "?";

                else
                	message = "Are you sure you want to proceed with the action?";
        }
 	var r = confirm(message);
        if (r == true) 
	{
		var apiurl = WP_RESTFUL_URL + "IWantTo/Workflow?Url=" + escape(url) + "&entity=" + escape(entity) + "&action=" + escape(action) + "&taskid=" + taskid + "&comments=" + escape(comments);
                $.ajax({
        		url: apiurl,
                	type: "Get",
                	success: successcb,
                	error: failurecb
            		});
		}
            	function successcb(msg) {
                if (msg.Status) 
		{

                	if (action == "Reject") 
			{
                       		//alert(msg.Message);
                	        document.getElementById(divid).innerHTML = "<br/><br/><p style='color: red;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>"+msg.btnMessage+"</p><br/><br/>";
                    	}
                    	else if (action == "Approve") 
			{
                        	//alert(msg.Message);
                        	document.getElementById(divid).innerHTML = "<br/><br/><p style='color: green;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>"+msg.btnMessage+"</p><br/><br/>";
                    	}
                    	else 
			{
                        	//alert(msg.Message);
                        	document.getElementById(divid).innerHTML = "<br/><br/><p style='color: green;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>" + msg.btnMessage + "</p><br/><br/>";
                    	}

 			//setTimeout(function(){smartstream.updateNotifactionDetail(NotificationId,'U',TargetId,'smartstream');}, 3000);

                }
                else 
		{
                    alert(msg.Message);
                }
	}
        function failurecb(msg) 
	{
        	alert("Operation Failed");
        }
}

function GeneralNotificationAction(ApiUrl, Id, ActionName , divid)
{
	var message = "Are you sure you want to " + ActionName.toLowerCase() + "?";
	var r = confirm(message);

	if (r == true) 
	{
    		var request = $.ajax({
        	type: "POST",
        	url: WP_RESTFUL_URL + ApiUrl,
        	data: { "AppId": Id, "Action": ActionName },
        //success: fnOnPostSuccess,
        //error: fnOnPostFailure
    		});
		request.done(function (msg) 
		{
   			if(msg) 
			{
				if (ActionName == "Reject") 
				{
                        		//alert(msg.Message);
                        		document.getElementById(divid)
divid.parentNode.innerHTML = "<br/><br/><p style='color: red;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>Rejected</p><br/><br/>";
                    		}
                    		else if (ActionName == "Approve") 
				{
                        		//alert(msg.Message);
                        		document.getElementById(divid)
divid.parentNode.innerHTML = "<br/><br/><p style='color: green;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>Approved</p><br/><br/>";
	                	}
			}
   			else
			alert("Action cannot be completed");
		});
	}
	function fnOnPostSuccess(msg) 
	{
        	if (msg.Status)
            		alert("Your Action has been completed");
        	else
            		alert("Action cannot be completed");
        		//Update old Notification - Hide it
    	}
    	function fnOnPostFailure(msg) 
	{
        	alert("Operation Failed");
        	//Display Message
    	}
}



function UpdateNotificationAction(apiUrl, communityID, ID, users, actionName, divid) {
    var message = "Are you sure you want to " + actionName.toLowerCase() + "?";
    var r = confirm(message);
    var actionStatus = 0;
    if (actionName == "Reject") {
        actionStatus = 1;
    }
    else if (actionName == "Approve") {
        actionStatus = 0;
    }
    if (r == true) {
        var request = $.ajax({
            type: "PUT",
            url: WP_RESTFUL_URL + apiUrl,
            data: { "communityId": communityID, "pendingUser": users, "ActionStatus": actionStatus, "notificationId": ID },
            //success: fnOnPostSuccess,
            //error: fnOnPostFailure
        });
        request.done(function (msg) {
            if (msg) {
                if (actionName == "Reject") {
                    if (msg.ResponseCode == "WP1008") {
                        $("div[id^=" + divid + "]").each(function (i, elem) { elem.innerHTML = "<br/><br/><p style='color: red;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>Rejected</p><br/><br/>"; });
                        //document.getElementById(divid).innerHTML = "<br/><br/><p style='color: red;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>Rejected</p><br/><br/>";
                        setTimeout(function () { smartstream.updateNotifactionDetail(ID, 'U', msg.ActionperformerID, 'smartstream'); }, 3000);
                    }
                    else {
                        document.getElementById(divid).innerHTML = "<br/><br/><p style='color: red;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>" + msg.ResponseMessage + "</p><br/><br/>";
                    }
                }
                else if (actionName == "Approve") {
                    if (msg.ResponseCode == "WP1008") {
                        $("div[id^=" + divid + "]").each(function (i, elem) { elem.innerHTML = "<br/><br/><p style='color: green;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>Approved</p><br/><br/>"; });
                        //document.getElementById(divid).innerHTML = "<br/><br/><p style='color: green;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>Approved</p><br/><br/>";
                        setTimeout(function () { smartstream.updateNotifactionDetail(ID, 'U', msg.ActionperformerID, 'smartstream'); }, 3000);
                    }
                    else {
                        document.getElementById(divid).innerHTML = "<br/><br/><p style='color: red;  background-color: #ffffff;  font-family: Arial,sans-serif;  font-weight:bold;  line-height:14px;  font-size: 12px;  margin: 0px;'>" + msg.ResponseMessage + "</p><br/><br/>";
                    }
                }

            }
            else
                alert("Action cannot be completed");
        });
    }
    function fnOnPostSuccess(msg) {
        if (msg.Status)
            alert("Your Action has been completed");
        else
            alert("Action cannot be completed");
        //Update old Notification - Hide it
    }
    function fnOnPostFailure(msg) {
        alert("Operation Failed");
        //Display Message
    }
}
